import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';

class HomeBanner extends StatelessWidget {
  const HomeBanner({super.key, required this.bannerList});

  // 定义数据接收
  final List bannerList;

  @override
  Widget build(BuildContext context) {
    return CarouselSlider(
        items: bannerList
            .map((item) => GestureDetector(
                  onTap: () {
                    Navigator.pushNamed(context, '/search');
                  },
                  child: Container(
                    margin: const EdgeInsets.only(left: 5, right: 5),
                    child: Image.network(item['imgUrl']),
                  ),
                ))
            .toList(),
        options: CarouselOptions(
            height: 160,
            autoPlay: true,
            autoPlayInterval: const Duration(seconds: 3)));
  }
}
